package com.chengh.nami.core.async;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PreDestroy;

/**
 * 确保应用退出时能关闭后台线程
 *
 * @author chengh
 */
@Component
@Slf4j
public class ShutdownManager {

    @PreDestroy
    public void destroy()
    {
        shutdownAsyncManager();
    }

    /**
     * 停止异步执行任务
     */
    private void shutdownAsyncManager() {
        log.info("关闭后台任务线程池");
        AsyncManager.me().shutdown();
    }
}
